<?php
namespace app\common\phpmail;
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/5 0005
 * Time: 15:32
 */
use think\Controller;
use Dm\Request\V20151123 as Dm;
include_once EXTEND_PATH.'aliyun-php-sdk-core/Config.php';
class SendEmail extends Controller
{
    public function sendEmail($content,$sender,$recipients,$theme)
    {
        //需要设置对应的region名称，如华东1（杭州）设为cn-hangzhou，新加坡Region设为ap-southeast-1，澳洲Region设为ap-southeast-2。
        $iClientProfile = \DefaultProfile::getProfile("cn-hangzhou", "LTAIjacJ4JILEMMU", "mo5MqPUEEFlyqTmkLFEaWDmfyfU2ou");
        //新加坡或澳洲region需要设置服务器地址，华东1（杭州）不需要设置。
        //$iClientProfile::addEndpoint("ap-southeast-1","ap-southeast-1","Dm","dm.ap-southeast-1.aliyuncs.com");
        //$iClientProfile::addEndpoint("ap-southeast-2","ap-southeast-2","Dm","dm.ap-southeast-2.aliyuncs.com");
        $client = new \DefaultAcsClient($iClientProfile);
        $request = new Dm\SingleSendMailRequest();
        //新加坡或澳洲region需要设置SDK的版本，华东1（杭州）不需要设置。
        //$request->setVersion("2017-06-22");
        $request->setAccountName("qilinxuan@mail.qilinxuan.net");
        $request->setFromAlias($sender); //发件人
        $request->setAddressType(1);
        $request->setTagName("qilinxuan"); //签名
        $request->setReplyToAddress("true");
        $request->setToAddress($recipients); //收件人地址
        $request->setSubject($theme); //邮件主题
        $request->setHtmlBody($content);   //邮件内容
        try {
            $response = $client->getAcsResponse($request);
            return ['code'=>1,'msg'=>$response];
        }
        catch (ClientException  $e) {
            return json(['code'=>$e->getErrorCode(),'msg'=>$e->getErrorMessage()]);
        }
        catch (ServerException  $e) {
            return json(['code'=>$e->getErrorCode(),'msg'=>$e->getErrorMessage()]);
        }
    }

}